//link:https://codeforc.es/contest/1559/problem/A
#include <iostream>
#include <vector>
#include <string.h>
#include<algorithm>
#include<set>
#define _  ios_base::sync_with_stdio(0),cin.tie(0)
using namespace std;
int main()
{
	_;
	int t, n,x,y;
	cin >> t;
	while (t--)
	{
		cin >> n;
		set<int>a;
		while (n--)
		{
			cin >> x;
			a.insert(x);
		}
		set<int>::iterator ai=a.begin();
		y = *ai;
		for (ai = a.begin(); ai != a.end(); ++ai)
		{
			y &= *ai;
		}
		cout << y << endl;
	}

}
